package com.snap.awesomeserial.serial;

import android.util.Log;

public class CmdBean {

    private byte[] cmd;
    private SpCallback callback;
    private boolean priori;
    private int retryCount;

    public CmdBean(byte[] cmd, SpCallback callback) {
        this.cmd = cmd;
        this.callback = callback;
    }

    public byte[] getCmd() {
        return cmd;
    }

    public void setCmd(byte[] cmd) {
        this.cmd = cmd;
    }

    public SpCallback getCallback() {
        return callback;
    }

    public void setCallback(SpCallback callback) {
        this.callback = callback;
    }

    public boolean isPriori() {
        return priori;
    }

    public void setPriori(boolean priori) {
        this.priori = priori;
    }

    public int getRetryCount() {
        return retryCount;
    }

    public void setRetryCount(int retryCount) {
        this.retryCount = retryCount;
    }

    public void retryOnce() {
        this.retryCount++;
    }

    /**
     * 设备号 模块号 功能码都匹配
     */
    public boolean match(byte[] data) {
        if (data[2] != cmd[2]) {
            Log.e("CmdBean", "doesn't match ");
            return false;
        }
        if (data[5] != cmd[5] + 1) {
            Log.e("CmdBean", "doesn't match ");
            return false;
        }
        if (data[6] != cmd[6]) {
            Log.e("CmdBean", "doesn't match ");
            return false;
        }
        return true;
    }
}
